<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>颜色选择器</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            width: 300px;
            text-align: center;
        }
        h1 {
            color: #333;
            margin-bottom: 30px;
        }
        select {
            width: 100%;
            padding: 10px;
            margin-bottom: 20px;
            border: 2px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
        }
        button {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            width: 100%;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #45a049;
        }
        #colorText {
            margin-top: 30px;
            padding: 20px;
            font-size: 18px;
            font-weight: bold;
            border-radius: 5px;
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>颜色选择器</h1>
        <select id="colorSelect">
            <option value="">-- 请选择颜色 --</option>
            <option value="red">红色</option>
            <option value="yellow">黄色</option>
            <option value="blue">蓝色</option>
            <option value="green">绿色</option>
        </select>
        <button onclick="changeColor()">确定</button>
        <div id="colorText">这里会显示您选择的颜色</div>
    </div>

    <script>
        function changeColor() {
            const colorSelect = document.getElementById("colorSelect");
            const colorText = document.getElementById("colorText");
            const selectedColor = colorSelect.value;
            
            if (!selectedColor) {
                alert("请先选择一个颜色！");
                return;
            }
            
            // 设置文字颜色和背景色
            colorText.style.color = selectedColor;
            colorText.textContent = `您选择了${colorSelect.options[colorSelect.selectedIndex].text}！`;
            
            // 根据颜色调整背景色以获得更好的可视性
            if (selectedColor === "yellow") {
                colorText.style.backgroundColor = "#ffffcc";
            } else {
                colorText.style.backgroundColor = "#f9f9f9";
            }
        }
    </script>
</body>
</html>